﻿#region Imports
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Windows.Data;
using System.Windows.Media;
#endregion Imports

namespace BookManager.Converters
{
    public class RatingStarConverter : IValueConverter
    {
        #region IValueConverter Members
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            int rating = -1;
            Int32.TryParse(System.Convert.ToString(value), out rating);

            var lstColours = new List<Brush>();
            for (int i = 1; i <= 10; i++)
            {
                var bgColour = (i <= rating) ? Brushes.Green : Brushes.Transparent;
                lstColours.Add(bgColour);
            }

            return lstColours.Select(bgc => new { BgCol = bgc }).ToList();
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
        #endregion IValueConverter Members
    }
}
